#include <bits/stdc++.h>
using namespace std;
const int maxn=100005;
int d[maxn],v[maxn],a[maxn],p[maxn];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;
    cin>>T;
    while(T--){
        int n,m,L,V;
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;i++)
            cin>>d[i]>>v[i]>>a[i];
        for(int i=1;i<=m;i++)
            cin>>p[i];
        int ans=0;
        for(int i=1;i<=n;i++){
            if(v[i]>V && p[m]>=d[i])
                ans++;
        }
        cout<<ans<<' '<<m-1<<endl;
    }
    return 0;
}
